package com.zrrd.zuo.kmp;

/**
 * @author ywb
 * @Description:
 * @date 2023/5/1 22:24
 */

public class Class02_TreeEqual {
    public static class Node {
        public int value;
        public Node left;
        public Node right;

        public Node(int v) {
            value = v;
        }
    }
    //small是不是big的子串 暴力方式
    public static boolean containsTree1(Node big, Node small) {
        if (small == null) {
            return true;
        }
        if (big == null) {
            return false;
        }
        if (isSameValueStructure(big, small)) {
            return true;
        }
        return containsTree1(big.left, small) || containsTree1(big.right, small);
    }
    public static boolean isSameValueStructure(Node head1, Node head2){
        if(head1 == null && head2 == null){
            return true;
        }
        if(head1 == null && head2 != null){
            return false;
        }
        if(head1 != null && head2 == null){
            return false;
        }
        if (head1.value != head2.value) {
            return false;
        }
        return isSameValueStructure(head1.left,head2.left) && isSameValueStructure(head1.right,head2.right);
    }
    //改进算法 先前序遍历再通过kmp算法看是否为子串

}
